package com.nosweattechnet.placemap;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nosweattechnet.datatypes.Place;

//Scales the Image to fit the screen, and scales 
public class MapScaler {
	Place place;
	PlaceMap pmap;
	float xscale;
	float yscale;
	float fullxscale;
	float fullyscale;
	public MapScaler(Place p,Context c,float swidth,float sheight,float fullwidth,float fullheight){
		place=p;
		//Gets the image from the Place
		Bitmap bmp = p.getPlaceMap(c);
		
		//Gets the height and width of the image
		float iwidth=bmp.getWidth();
		float iheight=bmp.getHeight();
		
		//Scales the image
        Bitmap scaled = Bitmap.createScaledBitmap(bmp, (int)swidth, (int)sheight, true);
        
        //Creates the PlaceMap
        pmap=new PlaceMap(c,scaled);
        pmap.setScaleType(ImageView.ScaleType.FIT_XY);
        
        //Computes the scale for the PlaceMap for the small and full size versions
        xscale=swidth/iwidth;
        yscale=sheight/iheight;
        fullxscale=fullwidth/iwidth;
        fullyscale=fullheight/iheight;
	}
	
	//Returns the PlaceMap
	public PlaceMap getPlaceMap(){
		return pmap;
	}
	
	//Scales coordinates to match the scaled image
	public float computeItemXCoordiantes(float x){
		return (x*xscale);
	}
	
	public float computeItemYCoordiantes(float y){
		return (y*yscale);
	}
	
	//Converts the scaled coordinates to coordinates of the Image
	public float undoXScale(float x){
		return x/fullxscale;
	}
	public float undoYScale(float y){
		return y/fullyscale;
	}
}
